package com.xxxx.send.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ需要一个交换机，一个队列，还有交换机和队列做绑定
 * Created by HMF on 2021/08/16 18:40
 */
@Configuration
public class RabbitMQConfig {

    // 声明 队列
    @Bean
    public Queue queue() {
        return new Queue("amqp_queue");
    }

    // 声明 交换机
    @Bean
    public TopicExchange topicExchange() { // 使用主题对列
        return new TopicExchange("amqp_exchange");
    }

    // 绑定队列和交换机
    @Bean
    public Binding binding() {
        // 绑定上面的队列和交换机
        return BindingBuilder.bind(queue()).to(topicExchange()).with("*.amqp.#");
    }
}
